package yunquan.wang.base.web.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.data.domain.Page;

public class PageTaglib extends TagSupport {

	private Page page;

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public int doEndTag() throws JspException {
		JspWriter out = pageContext.getOut();
	int pagesize=	page.getSize();
		if (page != null) {
			StringBuffer sbf = new StringBuffer();
			sbf.append("<div class=\"panelBar\">")
					.append("<div class=\"pages\">")
					.append("<span>显示</span>")
					.append("<select class=\"combox\" name=\"numPerPage\" onchange=\"navTabPageBreak({numPerPage:this.value})\">")
					.append("<option value=\"20\" " );
			if(pagesize==20) sbf.append(" selected");
							sbf.append(">20</option>")
					.append("<option value=\"50\" "  );
							if(pagesize==50) sbf.append(" selected");
							sbf.append(">50</option>")
					.append("<option value=\"100\" ");
							if(pagesize==100) sbf.append(" selected");
							sbf.append(">100</option>")
					.append("</select>")
					.append("<span>条，共" + page.getTotalElements() + "条</span>")
					.append("</div>")

					.append("<div class=\"pagination\" targetType=\"navTab\" totalCount=\""
							+ page.getTotalElements()
							+ "\" numPerPage=\""
							+ page.getSize()
							+ "\" pageNumShown=\""+page.getSize()+"\" currentPage=\""
							+ (page.getNumber()+1) + "\"></div>")

					.append("</div>");

			try {
				out.print(sbf.toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return EVAL_PAGE;
	}

}
